package com.sicaolong.service;

import com.sicaolong.context.RequestContext;
import com.sicaolong.event.commercial.CommercialEvent;
import com.sicaolong.eventdefine.model.Sender;
import com.sicaolong.model.req.SclRequest;
import com.sicaolong.model.req.User;
import com.sicaolong.model.rsp.AdMaterial;
import com.sicaolong.model.rsp.AdResponse;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

@Component
public class QueryAdServiceImpl implements QueryAdService {
    @Resource(name = "scl.local.sender")
    private Sender sender;


    public AdResponse queryAd(SclRequest sclRequest) {
        User user = sclRequest.getUser();
        AdResponse sclResponse = new AdResponse();
        for (String docId : sclRequest.getDocIdList()) {
            AdMaterial build = AdMaterial.builder().docId(docId).text(docId + "_" + System.currentTimeMillis()).build();
            sclResponse.getSclResponseDetail().getAdMaterialList().add(build);
        }
        sclResponse.setUser(user);
        return sclResponse;
    }

    public AdResponse queryAdV2(SclRequest sclRequest) {
        RequestContext requestContext = new RequestContext();
        requestContext.setOriRequest(sclRequest);
        CommercialEvent commercialEvent = new CommercialEvent();
        commercialEvent.setRequestContext(requestContext);
        sender.send(commercialEvent);
        return new AdResponse();
    }


}
